<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML>
<html>
<head>
<title>读者列表</title>
    <link href="../css/table.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${basePath}js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="${basePath}js/table.js"></script>
</head>

<script type="text/javascript">
	function editReader() {
		var radios = document.getElementsByName("choosen");
		var readerId = "";
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].checked == true) {
				readerId = radios[i].value;
				break;
			}
		}
		if (readerId == "") {
			alert("请选择需要操作的读者");
		} else {
			document.getElementById("readerId").value = readerId;
			document.operationForm.action = "${basePath}reader/getReader";
			document.operationForm.submit();
		}
	}

	function deleteReader() {
		var radios = document.getElementsByName("choosen");
		var readerId = "";
		for (var i = 0; i < radios.length; i++) {
			if (radios[i].checked == true) {
				readerId = radios[i].value;
				break;
			}
		}
		if (readerId == "") {
			alert("请选择需要操作的读者");
		} else if (confirm('确认删除吗？')) {
			document.getElementById("readerId").value = readerId;
			document.operationForm.action = "${basePath}reader/deleteReader";
			document.operationForm.submit();
		}
	}

	function addReader() {
		window.location.href = '${basePath}reader/toAddReader';
	}

	function listReader() {
		window.location.href = '${basePath}reader/getAllReader';
	}
</script>
<body>
	<h2>读者信息列表</h2>
	<form action="${basePath}reader/Reader_getReaderSearch" method="post">
		<s:textfield name="keyword" label="查询读者:" />
		<s:submit value="查询" />
	</form>
	<hr>
	<table>
		<thead>
			<tr>
				<th></th>
				<th>编号</th>
				<th>姓名</th>
				<th>类别</th>
				<th>电话</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="list" items="${readerList}">
				<tr>
					<td><input type="radio" name="choosen" value="${list.id}"></td>
					<td>${list.id}</td>
					<td>${list.name}</td>
					<td>${list.readerType.name}</td>
					<td>${list.phone}</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
    <form name="operationForm" action="" method="post" class="anniu">
        <input type="hidden" id="readerId" name="readerId" value=""> <input
            type="button" onclick="javascript:addReader()" value="新增"> <input
            type="button" onclick="javascript:editReader()" value="修改"> <input
            type="button" onclick="javascript:deleteReader()" value="删除">
        <input type="button" onclick="javascript:listReader()" value="所有读者">
    </form>
</body>
</html>